#ifndef ITEMMODEL_H
#define ITEMMODEL_H

#include <QtCore/QAbstractItemModel>
#include "item.h"

class QDomElement;
class QModelIndex;
class QVariant;
class QMimeData;

const QString dragDataType = QString("application/pDElement");

class ItemModel : public QAbstractItemModel
{
	Q_OBJECT

public:
	ItemModel(QObject* parent) : QAbstractItemModel(parent){ mRoot = new ListItem(); }
	~ItemModel(){ if (mRoot) delete mRoot; }
	bool loadData(const QString& xmlFile);

	//for View
	Qt::ItemFlags flags(const QModelIndex &index) const;
	QVariant data(const QModelIndex &index, int role) const;
	//QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

	QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
	QModelIndex parent(const QModelIndex &child) const;

	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	int columnCount(const QModelIndex &parent = QModelIndex()) const;

	//for Drag and Drop
	QStringList mimeTypes() const;
	QMimeData *mimeData(const QModelIndexList & indexes) const;
    
private:
	bool loadChildData(const QDomElement& e, Item* father);
	Item *mRoot;
};

#endif // ITEMMODEL_H